package xu.ye.dao;

import xu.ye.bean.TypeBean;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.agent.crm.db.DBInitScript;
import com.agent.crm.db.DatabaseManager;

public class TypeInfoDao {
	private DatabaseManager manager = null;
	public TypeInfoDao(Context context){

		//this.context = context;
		if(null==manager){
			manager = new DatabaseManager(context);
		}
	}
	
	public int getTypeInfoSize(){
		SQLiteDatabase database = manager.getWritableDatabase();
		Cursor cursor = database.query(DBInitScript.Table_TypeInfo, null, null, null, null, null, null);
		int count =cursor.getCount();
		cursor.close();
		database.close();
		return count;
	}
	
	public void initTypeInfoData(TypeBean tb){
		 SQLiteDatabase database = manager.getWritableDatabase();
		 try {
			 ContentValues values = new ContentValues();
	         values.put("type_name", tb.getTypeName());
	         values.put("sys_config", tb.getSysConfig());
	         database.insert(DBInitScript.Table_TypeInfo, null, values);
		} catch (Exception e) {
			// TODO: handle exception
		}finally{
		}
         database.close();
	}
	
	/**
	 *关闭DB
	 */
	public void destoryDB(){
		if(manager != null){
			manager.close();
		}
	}
}
